/*
 * @Author: sunzhijun 
 * @Date: 2019-08-08 14:59:53 
 * @Last Modified by: sunzhijun
 * @Last Modified time: 2019-11-27 19:53:31
 */

export default class TableHeaderAction {
    constructor(comp) {
        this.comp = comp;
        this.dispatch = this.comp.props.dispatch;
    }
    
    //增加行
    addRows = async ( moduleId )=>{
        const { props } = this.comp;
        const { cardTable, main } = props;
        let { hi_psnjob_h, pk_org } = main;
        let res = await this.dispatch({
            type: 'main/subAddAction',
            payload: {
                func_type: 5,		
                pk_org: pk_org,		
                psnjobForm: hi_psnjob_h,	
                table_code: moduleId
            }
        })
        if( res.success ){
            let data = res.data.grid ?res.data.grid: res.data;
            let moduleData = data[moduleId] && data[moduleId].rows[0].values;
            cardTable.addRow(moduleId, 0 , moduleData, false); 
        }
    }

    //删除行
    deleteRows = ( moduleId ) => {
        const { props } = this.comp;
        const { cardTable } = props;
        let getCheckedData = cardTable.getCheckedRows(moduleId);
        if( getCheckedData.length > 0){
            let deleteRowsIndex = [];
            getCheckedData.map((item ,index) => {
                deleteRowsIndex.push(item.index)
            })
            cardTable.delRowsByIndex(moduleId, deleteRowsIndex);
        }

    }
}